package com.example.diagnose.Controller;

import cn.hutool.json.JSONUtil;
import com.example.diagnose.Config.CommonResponse;
import com.example.diagnose.Config.ErnieBotTurboStreamParam;
import com.example.diagnose.Domain.Article;
import com.example.diagnose.Domain.BaiduChatMessage;
import com.example.diagnose.Domain.DiagnoseRecord;
import com.example.diagnose.Domain.FavoriteArticle;
import com.example.diagnose.Dto.Record;
import com.example.diagnose.Mapper.DiagnoseRecordMapper;
import com.example.diagnose.Service.DiagnoseRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/diagnose_record")
@Tag(name = "诊断记录模块")
public class DiagnoseRecordController {
    @Resource
    DiagnoseRecordService diagnoseRecordService;

    @Operation(summary = "获取用户诊断记录")
    @GetMapping("/{account}")
    public CommonResponse<List<Record>> getDiagnoseRecordByAccount(@PathVariable("account") String account) {
        List<Record> recordList = new ArrayList<Record>();
        List<DiagnoseRecord> diagnoseRecordList = diagnoseRecordService.getDiagnoseRecordByAccount(account);
        for (DiagnoseRecord dr : diagnoseRecordList){
            Record record = new Record(dr);
            recordList.add(record);
        }
        return CommonResponse.BackForSuccess("获得用户诊断记录成功", recordList);
    }

    @Operation(summary = "添加用户诊断记录")
    @PostMapping
    public CommonResponse<DiagnoseRecord> addDiagnoseRecord(@RequestBody DiagnoseRecord diagnoseRecord){
        int result = diagnoseRecordService.addDiagnoseRecord(diagnoseRecord);
        if(result == 0){
            return CommonResponse.BackForError("添加用户诊断记录失败");
        }else{
            return CommonResponse.BackForSuccess("添加用户诊断记录成功","http://127.0.0.1:8081/diagnose_record");
        }
    }

}

